<?php
class ShowchartAction extends CommonAction {
    function _filter(&$map){
        //$map['id'] = array('gt',1);
        //$map['wymc'] = array('like',"%".$_POST['wymc']."%");
    }
    public function index() {
        //列表过滤器，生成查询Map对象
        $map = $this->_search();
        if (method_exists($this, '_filter')) {
            $this->_filter($map);
        }
        //$name = $this->getActionName();
        $model = D('Examinfo');
        if (!empty($model)) {
            $this->_list($model, $map);
        }        
        /////////////////////////////////////////////////
        $this->display();
        return;
    }
    public function showchart(){
        //读取学校数据，生成树形目录，显示学校-班级-学生
        //先生成一个数据库专门用于显示树形目录？？？？？
        $id     = I('id');
        $name   = 'score'.$id;
        $School = M($name);
        $list   = $School->Distinct(true)->field('schoolid as id,school as text')->order('school')->select();
        if($list){
            //$this->ajaxReturn($list,"成功！",1);
            echo json_encode($list);
        }else{
            $this->ajaxReturn(0,"错误！",0);
        }
    }

    public function chart1(){
         /* pChart library inclusions */ 
         vendor('pChart2.class.pData','','.class.php');
         vendor('pChart2.class.pDraw','','.class.php');
         vendor('pChart2.class.pImage','','.class.php'); 

         $schoolID  = I('schoolid');
         $examID    = I('examid');

         $exam      = M('Examinfo');
         $r_exam    = $exam->find($examid);
         $fieldList = explode(';',$r_exam['fieldList']);
         $knl       = explode(',', $fieldList[1]);
         //dump($fieldList);
         
        if($schoolID==103){
             /* Create and populate the pData object */
             $MyData = new pData();  
             $MyData->addPoints(array(4,VOID,22,12,8,3),"不熟练");  //各知识点组不熟练的学生的人数
             $MyData->addPoints(array(3,12,15,8,5,5),"基本熟练");   //各知识点组基本熟练的学生人数
             $MyData->addPoints(array(2,7,5,18,19,22),"非常熟练");  //同上
             //$MyData->setAxisName(0,"用于测试中文显示");          //Y轴标题，可以不要，显示位置太小
             //$MyData->addPoints(array("中文一","Feb","Mar","Apr","May","Jun"),"Labels");
             $MyData->addPoints($knl,"Labels");
             $MyData->setSerieDescription("Labels","知识点");
             $MyData->setAbscissa("Labels");


             /* Create the pChart object */
             $myPicture = new pImage(700,230,$MyData);
             $myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100));
             $myPicture->drawGradientArea(0,0,700,230,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20));

             /* Set the default font properties */
             $myPicture->setFontProperties(array("FontName"=>LANG_PATH."/fonts/simkai.ttf","FontSize"=>10));

             /* Draw the scale and the chart */
             $myPicture->setGraphArea(60,20,680,190);
             $myPicture->drawScale(array("DrawSubTicks"=>FALSE,"Mode"=>SCALE_MODE_ADDALL_START0));
             $myPicture->setShadow(FALSE);
             $myPicture->drawStackedBarChart(array("Surrounding"=>-15,"InnerSurrounding"=>15));

             /* Write a label */
             //$myPicture->writeLabel(array("Frontend #1","Frontend #2","Frontend #3"),1,array("DrawVerticalLine"=>TRUE)); 

             /* Write the chart legend */
             $myPicture->drawLegend(460,210,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

             /* Render the picture (choose the best way) */
             $myPicture->autoOutput("pictures/example.drawStackedBarChart.shaded.png"); 
        }
        if($schoolID==99){
             /* Create and populate the pData object */
             $MyData = new pData();  
             $MyData->addPoints(array(-4,VOID,VOID,12,8,3),"Probe 11");
             $MyData->addPoints(array(3,12,15,8,5,-5),"Probe 2");
             $MyData->addPoints(array(2,7,5,18,19,22),"Probe 3");
             $MyData->setSerieTicks("Probe 2",4);
             $MyData->setAxisName(0,"Temperatures");
             $MyData->addPoints(array("Jan","Feb","Mar","Apr","May","Jun"),"Labels");
             $MyData->setSerieDescription("Labels","Months");
             $MyData->setAbscissa("Labels");

             /* Create the pChart object */
             $myPicture = new pImage(700,230,$MyData);

             /* Draw the background */
             $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
             $myPicture->drawFilledRectangle(0,0,700,230,$Settings);

             /* Overlay with a gradient */
             $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
             $myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
             $myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));

             /* Add a border to the picture */
             $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
             
             /* Write the picture title */ 
             $myPicture->setFontProperties(array("FontName"=>LANG_PATH."/fonts/Silkscreen.ttf","FontSize"=>6));
             $myPicture->drawText(10,13,"drawAreaChart() - draw an area chart",array("R"=>255,"G"=>255,"B"=>255));

             /* Write the chart title */ 
             $myPicture->setFontProperties(array("FontName"=>LANG_PATH."/fonts/Forgotte.ttf","FontSize"=>11));
             $myPicture->drawText(250,55,"Average temperature",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

             /* Draw the scale and the 1st chart */
             $myPicture->setGraphArea(60,60,450,190);
             $myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
             $myPicture->drawScale(array("DrawSubTicks"=>TRUE));

             $myPicture->setFontProperties(array("FontName"=>LANG_PATH."/fonts/pf_arma_five.ttf","FontSize"=>6));
             $myPicture->drawAreaChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO));

             /* Draw the scale and the 2nd chart */
             $myPicture->setGraphArea(500,60,670,190);
             $myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
             $myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>TRUE));
             $myPicture->drawAreaChart();

             /* Write the chart legend */
             $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

             /* Render the picture (choose the best way) */
             $myPicture->autoOutput("pictures/example.drawAreaChart.png");  
        }
        if($schoolID==101){
              /* Create and populate the pData object */
             $MyData = new pData();  
             $MyData->addPoints(array(-4,VOID,VOID,12,8,3),"Probe 1");
             $MyData->addPoints(array(3,12,15,8,5,-5),"Probe 2");
             $MyData->addPoints(array(2,7,5,18,19,22),"Probe 3");
             $MyData->setSerieTicks("Probe 2",4);
             $MyData->setAxisName(0,"Temperatures");
             $MyData->addPoints(array("Jan","Feb","Mar","Apr","May","Jun"),"Labels");
             $MyData->setSerieDescription("Labels","Months");
             $MyData->setAbscissa("Labels");

             /* Create the pChart object */
             $myPicture = new pImage(700,230,$MyData);

             /* Draw the background */
             $Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
             $myPicture->drawFilledRectangle(0,0,700,230,$Settings);

             /* Overlay with a gradient */
             $Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
             $myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
             $myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));

             /* Add a border to the picture */
             $myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));
             
             /* Write the picture title */ 
             $myPicture->setFontProperties(array("FontName"=>LANG_PATH."/fonts/Silkscreen.ttf","FontSize"=>6));
             $myPicture->drawText(10,13,"drawStackedBarChart() - draw a stacked bar chart",array("R"=>255,"G"=>255,"B"=>255));

             /* Write the chart title */ 
             $myPicture->setFontProperties(array("FontName"=>LANG_PATH."/fonts/Forgotte.ttf","FontSize"=>11));
             $myPicture->drawText(250,55,"Average temperature",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

             /* Draw the scale and the 1st chart */
             $myPicture->setGraphArea(60,60,450,190);
             $myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
             $myPicture->drawScale(array("DrawSubTicks"=>TRUE,"Mode"=>SCALE_MODE_ADDALL));
             $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
             $myPicture->setFontProperties(array("FontName"=>LANG_PATH."/fonts/pf_arma_five.ttf","FontSize"=>6));
             $myPicture->drawStackedBarChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO,"Rounded"=>TRUE,"Surrounding"=>60));
             $myPicture->setShadow(FALSE);

             /* Draw the scale and the 2nd chart */
             $myPicture->setGraphArea(500,60,670,190);
             $myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
             $myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"Mode"=>SCALE_MODE_ADDALL,"DrawSubTicks"=>TRUE));
             $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
             $myPicture->drawStackedBarChart();
             $myPicture->setShadow(FALSE);

             /* Write the chart legend */
             $myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

             /* Render the picture (choose the best way) */
             $myPicture->autoOutput("pictures/example.drawStackedBarChart.png"); 
        }

    }

}

?>